import axios from 'axios'
import {message} from 'antd'

const baseURL = 'http://localhost:9090/movie'

function http(url, method = 'get', data) {
  axios.interceptors.request.use((config) => {
    // message.open({
    //   type: 'loading',
    //   content: '',
    //   duration: 0,
    //   className: 'mess'
    // })
    return config
  });
  url = baseURL + url
  return new Promise((resolve, reject) => {
    axios[method](url, data).then((res) => {
      message.destroy()
      resolve(res.data)
    }).catch(err => {
      message.destroy()
      message.error('加载失败')
      reject(err)
    })
  })
}

export default http